﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using YSC_Core.BLL.Domain.BackstageModels;
using YSC_Services.BLL.Services.Interfaces;

namespace YSC_Backstage_Web.Controllers
{
    /// <summary>
    /// 用户授权
    /// </summary>
    public class AuthorizationController : Controller
    {
        private IUserBackstageServices _rep;

        public AuthorizationController(IUserBackstageServices rep)
        {
            this._rep = rep;
        }

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <returns></returns>
        public IActionResult List()
        {
            return View();
        }

        /// <summary>
        /// 用户添加
        /// </summary>
        /// <returns></returns>
        public IActionResult BackstageAdd()
        {
            return View();
        }

        /// <summary>
        /// 授予角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult Edit(string id)
        {
            ViewData["Id"] = id;
            return View();
        }

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetRoleAll()
        {
            var ret = _rep.GetRoleAll(1, 1000, null);
            return Json(ret);
        }

        /// <summary>
        /// 用户角色授予
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="roleId"></param>
        /// <param name="roleAreCode">省市用户编码Core</param>
        /// <returns></returns>
        public JsonResult AddUserRole(string userId, string roleId, string roleAreCode, string remarks)
        {
            var ret = _rep.AddUserRole(userId, roleId, roleAreCode, remarks);
            return Json(ret);
        }

        /// <summary>
        /// 用户列表
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <param name="status">是否停用: -1 停用0: 正常 1: 认证用户 2:未认证</param>
        /// <param name="sasearch"></param>
        /// <param name="isAttest">认证类型 0 市场 1 :产地 </param>
        /// <returns></returns>
        public JsonResult GetUserAll(int index, int size, int status, string isAttest, string areCode, string sasearch)
        {
            var ret = _rep.GetUserAll(index, size, status, isAttest, areCode, sasearch);
            return Json(ret);
        }

        /// <summary>
        /// 后台用户添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult AddUpdateBackstageUser([FromBody]UserModels model)
        {
            var ret = _rep.AddUpdateBackstageUser(model);
            return Json(ret);
        }
    }
}